<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>工作台账</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <script src="./../js/index.js"></script>
    <style>
         body {
            font-size: 1rem;
        } 

        /* td {
            text-align: center;
        } */
    </style>
</head>

<body>
    <div id="app" class="container">
        <nav class="navbar bg-body-tertiary">
            <form class="container-fluid justify-content-start">
                <button class="btn btn-outline-success me-2 " type="button" onclick="to_demo()">台账</button>
                <button class="btn btn-outline-success me-2" type="button" onclick="to_demo1()">掉线</button>
                <button class="btn btn-outline-success me-2 active" type="button">测试</button>
            </form>
        </nav>



        <br>
        <div class="container-sm">
            <table class="table table-striped" id="myTable">
                <thead>
                    <!-- <tr>
                        <th>时间</th>
                        <th>车牌</th>
                        <th>速度</th>
                        <th>位置</th>
                    </tr> -->
                </thead>
                <tbody id="copyBtn">
                    <tr v-for="(item, index) in this.carCodeArray" :key="index">
                        <td class="col-sm-1">{{item.str1}}</td>
                        <td class="col-sm-2">{{item.str2}}</td>
                        <td class="col-sm-1">{{item.str3}}</td>
                        <td class="col-sm-8">{{item.str4}}</td>
                    </tr>

                </tbody>
            </table>

            <br>
            <br>
            <br>
            <!-- <div class="form-group"> -->
            <textarea class="form-control" rows="6" @keyup.enter="handleEnter" v-model="inputInfo" id="inputInfo"
                placeholder="新增有轨迹台账"></textarea>
            
            <!-- <textarea class="form-control" rows="3" @keyup.enter="handleEnter" v-model="inputStr" id="inputStr"
                placeholder="新增车牌"></textarea> -->
            <textarea class="form-control" rows="10" placeholder="暂存车牌"></textarea>
            <textarea class="form-control" rows="2" @keyup.enter="handleEnter" v-model="inputInfoNoData" id="inputInfo"
                placeholder="新增无轨迹台账"></textarea>

        </div>

    </div>
    <script src="./../js/vue.js"></script>
    <script>




        const app = new Vue({
            el: '#app',
            data: {
                msg: '您好，赵永利',
                carCodeArray: [],
                inputStr: '',
                inputInfo: '',
                inputInfoNoData: '',
                copyTextarea: '',
                carInfo: {
                    str1: '',
                    str2: '',
                    str3: '',
                    str4: ''
                }

            },
			created() {
                // 设置定时器每秒更新counter
                this.timer = setInterval(() => {
                   
                    this.addNodata()
                    this.getValue()
                }, 500);
            },

            beforeDestroy() {
                // 清除定时器以避免内存泄漏
                clearInterval(this.timer);
            },
            methods: {

                handleEnter() {
                    this.addNodata()
                    this.getValue()
                },


                addNodata() {
                    var strArray = this.inputInfoNoData.split(/\r\n|\n/)
                    if (this.inputInfoNoData.trim() === '') {
                        return
                    }

                    if (this.inputInfoNoData.trim().indexOf('定位位置') !== -1) {
                        return
                    }


                    str1 = strArray.filter(str => str.trim().indexOf('粤') !== -1)[0]
                    str3 = strArray.filter(str => str.trim().indexOf('km/h') !== -1)[0]
                    if (str3 === undefined) {
                        console.log(str3)
                        return
                    }
                    str2 = strArray[strArray.indexOf(str3) + 1]
                    console.log("==============addNodata==============")
                    console.log(str1)
                    console.log(str2)
                    carInfo = new Object();
                    carInfo.str1 = '1'
                    carInfo.str2 = str1.trim()
                    carInfo.str3 = 0
                    carInfo.str4 = str2.trim()
                    this.carCodeArray.push(carInfo)
                    this.inputInfo = ''
                    this.inputInfoNoData = ''

                },
                getValue() {

                    if (this.inputInfo.indexOf('粤') !== -1) {
                        // console.log("包含车牌----------------")

                    } else {
                        console.log("不包含车牌-------------")
                        return
                    }

                    if (this.inputInfo.indexOf('定位时间') !== -1) {
                        // console.log("包含定位时间----------------")

                    } else {
                        console.log("不包含定位时间-------------")
                        return
                    }

                    if (this.inputInfo.indexOf('行驶速度') !== -1) {

                        //console.log("包含行驶速度----------------")

                    } else {
                        console.log("不包行驶速度-------------")
                        return
                    }

                    if (this.inputInfo.indexOf('定位位置') !== -1) {
                        //console.log("包含定位位置----------------")

                    } else {
                        console.log("不包含定位位置-------------")
                        return
                    }



                    var strPosition1 = this.inputInfo.indexOf('粤')
                    //console.log("粤--所在位置："+strPosition1)
                    var strPosition2 = this.inputInfo.indexOf('驾')
                    //console.log("驾--所在位置："+strPosition2)

                    var str1 = this.inputInfo.substring(strPosition1, strPosition2).trim()

                    console.log("获取车牌：" + str1)


                    var strPosition3 = this.inputInfo.indexOf('定位时间:')
                    //console.log("粤--所在位置："+positionY)
                    var strPosition4 = this.inputInfo.indexOf('定位经度:')
                    //console.log("驾--所在位置："+positionJ)

                    var str2 = this.inputInfo.substring(strPosition3 + 16, strPosition4).trim()

                    console.log("获取定位时间：" + str2)

                    var strPosition5 = this.inputInfo.indexOf('定位位置:')
                    //console.log("驾--所在位置："+positionJ)

                    var str3 = this.inputInfo.substring(strPosition5 + 5).trim()

                    console.log("获取定位位置：" + str3)

                    var strPosition6 = this.inputInfo.indexOf('行驶速度:')
                    //console.log("粤--所在位置："+positionY)
                    var strPosition7 = this.inputInfo.indexOf('km/h')
                    //console.log("驾--所在位置："+positionJ)

                    var str4 = this.inputInfo.substring(strPosition6 + 5, strPosition7).trim()

                    console.log("获取行驶速度：" + str4)

                    var flag = true;

                    // for (var i = 0; i < this.carCodeArray.length; i++) {
                    //     this.carInfo = this.carCodeArray[i]
                    //     if (this.carInfo != "" && str1 === this.carInfo.str2) {
                    //         //if (this.carInfo.str1 == '' && this.carInfo.str3 == '' && this.carInfo.str4 == '') {

                    //         this.carInfo.str1 = str2
                    //         this.carInfo.str2 = str1
                    //         this.carInfo.str3 = Math.round(str4)
                    //         this.carInfo.str4 = str3
                    //         this.carCodeArray[i] = this.carInfo
                    //         console.log(this.carCodeArray)
                    //         flag = false;
                    //         break;

                    //         // }
                    //     }
                    // }
                    if (flag) {
                        console.log("flag==============" + flag)

                        carInfo = new Object();


                        carInfo.str1 = str2
                        carInfo.str2 = str1
                        carInfo.str3 = Math.round(str4)
                        carInfo.str4 = str3
                        this.carCodeArray.push(carInfo)

                    }

                    this.inputInfo = ''
                    this.inputInfoNoData = ''

                }
            }




        })



    </script>
    <script src="../js/bootstrap.bundle.min.js"></script>
</body>

</html>